package com.pdf.pdfserver.service.read.text.factory;

import com.pdf.pdfserver.enums.FileSuffixEnum;
import com.pdf.pdfserver.service.read.text.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author songfz
 * @Description 文件处理类工厂
 * @Date 2022/1/4
 */
@Service
public class FileProcessFactory {

    @Autowired
    private DocReadService docReadService;

    @Autowired
    private ExeclReadService execlReadService;

    @Autowired
    private PdfReadService pdfReadService;

    @Autowired
    private PowerPointReadService powerPointReadService;

    @Autowired
    private TxtReadService txtReadService;


    private final ConcurrentHashMap<FileSuffixEnum,IfReadService> map = new ConcurrentHashMap<>();


    @PostConstruct
    public void init(){

        map.put(FileSuffixEnum.DOC,this.docReadService);
        map.put(FileSuffixEnum.DOCX,this.docReadService);
        map.put(FileSuffixEnum.XLS,this.execlReadService);
        map.put(FileSuffixEnum.XLSX,this.execlReadService);
        map.put(FileSuffixEnum.PDF,this.pdfReadService);
        map.put(FileSuffixEnum.PPT,this.powerPointReadService);
        map.put(FileSuffixEnum.PPTX,this.powerPointReadService);
        map.put(FileSuffixEnum.TXT,this.txtReadService);
    }

    public IfReadService toBean(FileSuffixEnum suffixEnum){
        return map.get(suffixEnum);
    }
}
